package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.bo.ConsultBo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.ConsultMapper;
import com.java2207.group1.pojo.Consult;
import com.java2207.group1.service.ConsultService;
import com.java2207.group1.vo.consult.BarVo;
import com.java2207.group1.vo.consult.PieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Map;

@Service("consultService")
public class ConsultServiceImpl implements ConsultService {

    @Autowired
    private ConsultMapper consultMapper;

    @Override
    public LayuiPageVo<Consult> consultPageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        //mybatis 的分页插件
        PageHelper.startPage(page, limit);

        List<Consult> consults = consultMapper.selectByParams(params);

//        List<Student> students = studentMapper.studentList();

        //mybatis 的分页数据结构
        PageInfo<Consult> consultPageInfo = new PageInfo<>(consults);

        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中
        LayuiPageVo<Consult> consultLayuiPageVo = new LayuiPageVo<>();

        consultLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        consultLayuiPageVo.setMsg("分页列表数据");   // 提示信息
        consultLayuiPageVo.setCount(consultPageInfo.getTotal());     // 总记录数
        consultLayuiPageVo.setData(consultPageInfo.getList());    // 分页的列表数据

        return consultLayuiPageVo;
    }

    @Override
    public int deleteConsult(Integer id) {
        return consultMapper.deleteConsult(id);
    }

    @Override
    public int addConsult(Consult consult) {
        return consultMapper.addConsult(consult);
    }

    @Override
    public int updateConsult(Consult consult) {
        return consultMapper.updateConsult(consult);
    }

    @Override
    public int batchCon(String ids) {
        String[] arr = ids.split(",");
        return consultMapper.batchCon(arr);
    }

    @Override
    public List<BarVo> setBarData() {
        return consultMapper.setBarData();
    }

    @Override
    public List<PieVo> setPieData() {
        return consultMapper.setPieData();
    }

    @Override
    public List<ConsultBo> consultExcelData(Consult consult) {
        return consultMapper.consultExcelData(consult);
    }


}
